Apr 13, 2006, 08:10 PM // 20:10
|
#1
|
Ascalonian Squire
Join Date: Dec 2005
Guild: Epitomy Of Natural Evil
Profession: W/Mo
|
Newb coder needs help plz
It may just be that i have been writing c++ all day but i am stuck on this
it will be a very small program that will print
+_____+
_+___+
__+_+
___+
the catch, it must be done by for loops not a ton of cout's
toss me some code if any of you can, ty in advance
dont mind the "_" it was just a way for you to see the design, count the _ as spaces
Last edited by SlitUrNek; Apr 13, 2006 at 08:13 PM // 20:13..
|
|
|
Apr 13, 2006, 08:38 PM // 20:38
|
#2
|
Desert Nomad
|
if you still need it:
something like uh
char[7] print = (' ', ' ', ' ', ' ', ' ', ' ', ' ') //err, basically just create an array of chars and initialize it all to the space character.
for (int i = 0; i < 4; i++)
{
char[i] = '+';
char[7-i] = '+';
cout << char << endl; //this should print out the entire array of chars, if it doesn't uh, just make another for loop that iterates through each element and print that.
char[i] = '_';
char[7-i] = '_';
}
That should work, not sure if it fits all the criteria though.
|
|
|
Apr 13, 2006, 09:15 PM // 21:15
|
#3
|
Ascalonian Squire
Join Date: Dec 2005
Guild: Epitomy Of Natural Evil
Profession: W/Mo
|
i dont entirly understand the char[] i havent gotten that far yet here take a look at my other 2 patters if u can get a grasp
i was thinking of using setw(), but will setw hold a variable and not numeric and i would just through the setw through a loop for my spaces +/-
#include
#include //for setw
using namespace std;
int main ()
{
int col, row;
char mychar = '+';
//Pattern 1
for (col=1; col <= 5; ++col)
{
cout << endl;
for (row=0; row < col; ++row)
{
cout << mychar;
}
}
//Pattern 1 part 2
for (col=0; col <= 5; ++col)
{
cout << endl;
for (row=4; row >= col; --row)
{
cout << mychar;
}
}
//Pattern 2
cout << endl;
for (col=0; col < 5; ++col)
{
cout << endl;
for (row=0; row < 4 - col; ++row)
{
cout << " ";
}
for (row=0; row < 2 * col + 1; ++row)
{
cout << mychar;
}
}
//Pattern 3
cout << endl;
return 0;
}
Last edited by SlitUrNek; Apr 13, 2006 at 09:36 PM // 21:36..
|
|
|
Apr 13, 2006, 09:56 PM // 21:56
|
#4
|
Desert Nomad
|
err, well, a char[] is an array of chars.
Think of it this way char[7] means that you have an array of 7 slots, and their names are 0-7, so for example:
0 1 2 3 4 5 6 7
now: char[0] = 'a';
0 1 2 3 4 5 6 7
a
char[6] = 'b';
0 1 2 3 4 5 6 7
a b
you access them the same way.
char temp = char[0];
now temp will contain whatever is stored in char[0] which in this case is 'a'.
Now, if you're not allowed to use arrays, its going to be annoying. You'll probably have to do some for loops within for loops
|
|
|
Apr 13, 2006, 10:05 PM // 22:05
|
#5
|
Ascalonian Squire
Join Date: Dec 2005
Guild: Epitomy Of Natural Evil
Profession: W/Mo
|
well, this chapter is using for loops in c++ so i would asume that is what i am to do, i dont see why i cant cheat it a bit and use char[] eh?
if i am going to use char[] how do i declare each
exampl: char[7] = (' '; ' '; ' '; ' '; ' '; ' '; ' ')
so char will set each slot 0-6 will spaces?
or must i go through and declaire each one?
Last edited by SlitUrNek; Apr 13, 2006 at 10:13 PM // 22:13..
|
|
|
Apr 13, 2006, 10:53 PM // 22:53
|
#6
|
Desert Nomad
|
whoops, had a typo, if uh, you're using a char array, do
char[7] print;
for (int i = 0; i < 7; i++)
print[i] = ' ';
|
|
|
Apr 13, 2006, 11:07 PM // 23:07
|
#7
|
Ascalonian Squire
Join Date: Dec 2005
Guild: Epitomy Of Natural Evil
Profession: W/Mo
|
actualy i have figured it out with some help from a friend, if ur interested in what it was soposed to look like, here you go
for (col=0; col < 5; ++col)
{
cout << endl;
for (row=0; row < col; ++row)
{
cout << " ";
}
for (row =col; row <= col; ++row)
{
cout << "+";
}
for (row=0; row < 5 - col*2 ; ++row)
{
cout << " ";
}
for (row=col; row <4 ;row++ )
{
cout << "+";
break;
}
}
|
|
|
Apr 14, 2006, 10:16 PM // 22:16
|
#8
|
Krytan Explorer
Join Date: Aug 2005
Location: nowhere!!!
Profession: N/Mo
|
I would have done it this way, but I don't know if it would meet the requirements.
And make sure to remove any "_" symbols and replace them with spaces.
#include
#include
using namespace std;
int main()
{
int i;
for(i = 1; i != 0; i--)
{
cout << "+_____+" << endl;
Sleep(1000);
system("cls");
cout << " +___+ " << endl;
Sleep(1000);
system("cls");
cout << " +_+ " << endl;
Sleep(1000);
system("cls");
cout << " + " << endl;
Sleep(2000);
system("cls");
}
return 0;
system("pause");//Only for Dev C++ Compiler
}
Last edited by benmanhaha; Apr 14, 2006 at 10:20 PM // 22:20..
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
Similar Threads
|
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
Newb!?!
|
NightStalkerXT |
The Riverside Inn |
6 |
Nov 02, 2005 08:13 AM // 08:13 |
Help A Newb
|
3xtensions |
The Campfire |
3 |
Sep 19, 2005 06:33 PM // 18:33 |
skimo |
Questions & Answers |
4 |
Aug 18, 2005 08:31 PM // 20:31 |
TeamEllis |
The Riverside Inn |
6 |
Jul 27, 2005 05:54 AM // 05:54 |
All times are GMT. The time now is 12:50 AM // 00:50.
|